from urllib.request import Request
from starlette.responses import JSONResponse


def init_routes(app):
    @app.exception_handler(Exception)
    async def global_exception_handler(request: Request, exc: Exception):
        return JSONResponse(
            status_code=exc.status_code,
            content={
                "error": exc.__str__(),
                "detail": exc.detail,
                "path": request.url.path
            }
        )
